import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:nil/nil.dart';

class MCard extends StatelessWidget {
  final Widget? title;

  final IconData? icon;

  final Widget? right;

  void Function()? rightTap;

  Widget child;

  static const TextStyle defaultTitleStyle = TextStyle(
      fontSize: 16, color: Colors.black87, fontWeight: FontWeight.w600);

  static const TextStyle defaultRightTextStyle =
      TextStyle(fontSize: 12, color: Colors.black54);

  MCard({
    super.key,
    this.title,
    this.icon,
    this.right,
    this.rightTap,
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: const EdgeInsets.only(top: 20),
      color: Colors.white,
      surfaceTintColor: Colors.white,
      elevation: 6,
      shadowColor: Colors.black38,
      clipBehavior: Clip.hardEdge,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8),
      ),
      child: Container(
        padding:
            const EdgeInsets.only(top: 15, right: 15, bottom: 10, left: 15),
        child: Column(
          children: [
            title != null
                ? Container(
                    padding: const EdgeInsets.only(bottom: 10),
                    decoration: const BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                          color: Colors.black12,
                          width: 1,
                        ),
                      ),
                    ),
                    child: Row(
                      children: [
                        Expanded(
                          flex: 7,
                          child: Wrap(
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: [
                              icon != null
                                  ? Icon(
                                      icon,
                                      color: Colors.teal,
                                    )
                                  : nil,
                              Padding(
                                padding: const EdgeInsets.only(left: 10),
                                child: title,
                              ),
                            ],
                          ),
                        ),
                        right != null
                            ? InkWell(
                                onTap: rightTap,
                                child: Container(
                                  alignment: Alignment.centerRight,
                                  child: right,
                                ),
                              )
                            : nil,
                      ],
                    ),
                  )
                : nil,
            Container(
              padding: const EdgeInsets.only(top: 10),
              child: child,
            )
          ],
        ),
      ),
    );
  }
}
